package com.randy.recyclerviews.itemdecoration;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by joel on 16/5/31.
 * <p/>
 * Momo Tech 2011-2016 © All Rights Reserved.
 */
public class LinearItemDecoration extends RecyclerView.ItemDecoration {
    public int leftSpace;
    public int rightSpace;
    public int toSpace;
    public int bottomSpace;
    public int firstSpace;

    public LinearItemDecoration(int leftSpace, int topSpace, int rightSpace, int bottomSpace) {
        this.leftSpace = leftSpace;
        this.toSpace = topSpace;
        this.rightSpace = rightSpace;
        this.bottomSpace = bottomSpace;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        int position = parent.getChildAdapterPosition(view);
        if (position == 0) {
            outRect.left = firstSpace;
        } else {
            outRect.left = leftSpace;
        }
        outRect.top = toSpace;
        outRect.right = rightSpace;
        outRect.bottom = bottomSpace;
    }

    public void setFirstItemSpace(int space) {
        this.firstSpace = space;
    }
}